﻿// Copyright Microsoft

using System;
using System.Collections.Generic;
using System.Activities.Presentation.View;
using System.Activities.Presentation.Hosting;
using System.Activities.Presentation.Model;
using System.ComponentModel.Composition.Hosting;

namespace Microsoft.Samples.SqlServer.Workflow.Designer
{
  public class CustomEditorService : IExpressionEditorService
  {
    public ExpressionEditor instance = null;

    public void CloseExpressionEditors(){}

    public IExpressionEditorInstance CreateExpressionEditor(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces, List<ModelItem> variables, string text)
    {
      instance = new ExpressionEditor();
      instance.Text = text;
      return instance;
    }

    //Called to get ModelProperty modelProperty = modelItem.Properties["To"];
    public IExpressionEditorInstance CreateExpressionEditor(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces, List<ModelItem> variables, string text, System.Windows.Size initialSize)
    {
      //Hook into Assign activity
      instance = new ExpressionEditor();
      instance.Variables = variables;
      instance.Text = text;

      return instance;
    }

    public IExpressionEditorInstance CreateExpressionEditor(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces, List<ModelItem> variables, string text, Type expressionType)
    {
      instance = new ExpressionEditor();
      instance.Text = text;
      return instance;
    }


    //Called to get ModelProperty modelProperty = mi.Properties["Value"]; or "Value" property
    public IExpressionEditorInstance CreateExpressionEditor(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces, List<ModelItem> variables, string text, Type expressionType, System.Windows.Size initialSize)
    {
      instance = new ExpressionEditor();
      instance.Text = text;
      instance.Variables = variables;
      instance.ExpressionType = expressionType;
      return instance;
    }

    public void UpdateContext(AssemblyContextControlItem assemblies, ImportedNamespaceContextItem importedNamespaces){}
  }
}